import os
import json
from pathlib import Path


class ConfigManager:
    def __init__(self):
        self.config_path = Path.home() / ".word_learner_config.json"
        self.config = {
            "current_page": 1,
            "filter_status": "all",
            "show_all_definitions": False
        }
        self.load_config()

    def load_config(self):
        if self.config_path.exists():
            try:
                with open(self.config_path, 'r') as f:
                    self.config.update(json.load(f))
            except:
                pass

    def save_config(self):
        with open(self.config_path, 'w') as f:
            json.dump(self.config, f)

    def get(self, key, default=None):
        return self.config.get(key, default)

    def set(self, key, value):
        self.config[key] = value
        self.save_config()